<template>
	<!-- style="background: url(https://yummy.ruanxiakeji.cn/uploads/image/20230302/b4d7e8b5-8fd9-44d4-bfcd-4dd00b572e3e.jpg) no-repeat center/cover;" -->
	<view class="launch-bck" @click="goPage" :style="{background: bckImg}">
	</view>
</template>

<script>
	import Cache from '@/utils/cache'
	import {
		mapGetters,
	} from 'vuex'
	export default {
		data() {
			return {
				bckImg: '',
				timeout: null,
				shareCode: ""
			}
		},
		onLoad(option) {
			this.shareCode = option.share_code
			const {
				backgroundImg = ""
			} = Cache.get("_CONFIG") || {}
			this.bckImg = `url(${backgroundImg}) no-repeat center/cover`
			this.timeout = setTimeout(() => {
				this.goPage()
			}, 3 * 1000)
		},
		onUnload() {
			clearTimeout(this.timeout)
		},
		methods: {
			goPage() {
				clearTimeout(this.timeout)
				const {
					isAdmin,
					token
				} = this.userInfo || {}
				const share_code = this.shareCode
				if (token) {
					if (share_code) {
						uni.redirectTo({
							url: '/pages/bundle/coupon/coupon?share_code=' + share_code
						})
					} else if (isAdmin) {
						uni.redirectTo({
							url: '/pages/write_off/write_off'
						})
					} else {
						uni.switchTab({
							url: '/pages/index/index'
						});
					}
				}
			},
		},
		computed: {
			...mapGetters(["userInfo"]),
		}
	}
</script>

<style lang="scss">
	.launch-bck {
		position: fixed;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
	}
</style>
